from django.shortcuts import render
from .models import *
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *


# 登录
class YhViews(APIView):
    def post(self, request):
        user = request.data.get("user")
        pwd = request.data.get("pwd")
        ss = Yh.objects.filter(user=user).first()
        if ss and pwd == ss.pwd:
            return Response({"msg": "登陆成功"})
        else:
            return Response({'msg': '登录失败'})


class XsViews(APIView):
    def get(self,request):
        xs_li = Xs.objects.all().values()
        return Response({"xs_li": xs_li})


    def post(self,request):
        xs_lii = Xsser(data=request.data)
        xs_lii.is_valid(raise_exception=True)
        xs_lii.save()
        return Response({'msg':"添加成功"})